// https://leetcode.cn/problems/sum-of-two-integers/description/

// 算法思路总结：
// 1. 使用位运算实现加法
// 2. 异或运算计算无进位和
// 3. 与运算左移1位计算进位值
// 4. 循环直到进位为0，返回结果
// 5. 时间复杂度：O(1)，空间复杂度：O(1)

#include <iostream>
using namespace std;

class Solution 
{
public:
    int getSum(int a, int b) 
    {
        while (b)
        {
            int tmp = a ^ b;
            int carry = (a & b) << 1;
            a = tmp;
            b = carry;
        }
        return a;
    }
};

int main()
{
    int a1 = 1, b1 = 2;
    int a2 = 2, b2 = 3;

    Solution sol;
    cout << sol.getSum(a1, b1) << endl;
    cout << sol.getSum(a2, b2) << endl;

    return 0;
}